package com.quxing.amazon.controller;


import cn.hutool.core.lang.tree.Tree;
import com.quxing.amazon.common.Result;
import com.quxing.amazon.model.Category;
import com.quxing.amazon.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 亚马逊商品分类 前端控制器
 * </p>
 *
 * @author zhb
 * @since 2021-05-09
 */
@Api(tags = "分类接口")
@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
public class CategoryController {

    private final CategoryService categoryService;

    @ApiOperation("获取树形分类")
    @GetMapping("/tree")
    public Result<List<Tree<Integer>>> trees() {
        return Result.success(categoryService.trees());
    }

    @ApiOperation("根据父id获取指定菜单列表")
    @GetMapping("/list")
    public Result<List<Category>> listByParentId(@RequestParam(defaultValue = "0") Integer parentId) {
        return Result.success(categoryService.listByParentId(parentId));
    }


}
